package com.ruoyi.project.module.bydservice.controller;

import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.bydservice.domain.Bydservice;
import com.ruoyi.project.module.bydservice.service.IBydserviceService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 客服 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-14
 */
@Controller
@RequestMapping("/module/bydservice")
public class BydserviceController extends BaseController
{
    private String prefix = "module/bydservice";

	@Autowired
	private IBydserviceService bydserviceService;
	
	@RequiresPermissions("module:bydservice:view")
	@GetMapping()
	public String bydservice()
	{
	    return prefix + "/bydservice";
	}
	
	/**
	 * 查询客服列表
	 */
	@RequiresPermissions("module:bydservice:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Bydservice bydservice)
	{
		startPage();
        List<Bydservice> list = bydserviceService.selectBydserviceList(bydservice);
		return getDataTable(list);
	}
	@Log(title = "参数管理", businessType = BusinessType.EXPORT)
	@RequiresPermissions("system:bydservice:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(Bydservice bydservice) throws Exception
	{
		try
		{
			List<Bydservice> list = bydserviceService.selectBydserviceList(bydservice);
			ExcelUtil<Bydservice> util = new ExcelUtil<Bydservice>(Bydservice.class);
			return util.exportExcel(list, "bydservice");
		}
		catch (Exception e)
		{
			return error("导出Excel失败，请联系网站管理员！");
		}
	}
	/**
	 * 新增客服
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存客服
	 */
	@RequiresPermissions("module:bydservice:add")
	@Log(title = "客服", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Bydservice bydservice)
	{		
		return toAjax(bydserviceService.insertBydservice(bydservice));
	}

	/**
	 * 修改客服
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Bydservice bydservice = bydserviceService.selectBydserviceById(id);
		mmap.put("bydservice", bydservice);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存客服
	 */
	@RequiresPermissions("module:bydservice:edit")
	@Log(title = "客服", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Bydservice bydservice)
	{		
		return toAjax(bydserviceService.updateBydservice(bydservice));
	}
	
	/**
	 * 删除客服
	 */
	@RequiresPermissions("module:bydservice:remove")
	@Log(title = "客服", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(bydserviceService.deleteBydserviceByIds(ids));
	}
	
}
